unit GlavnaKnjigaRpt;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, DBBaseRpt, DokumentRpt, ExcelRpt, EXLReportExcelTLB, EXLReportBand, EXLReport, DB, DBClient,
  alBaseDataSet, MConnect;

type
  TrptGlavnaKnjiga = class(TrptDokument)
    procedure OnFormatCell(Sender: TObject; Band: TEXLReportBand;
      RowInTemplate, RowInReport, ColumnInReport: Integer; Report: _Worksheet;
      const CellValue: OleVariant);
  private
    { Private declarations }
  protected
    function GetSessionParamRelations(DataSet: TDataSet): TSessionParamRelations; override;
    procedure Initialize; override;
  public

  end;

var
  rptGlavnaKnjiga: TrptGlavnaKnjiga;

implementation

{$R *.dfm}

{ TrptGlavnaKnjiga }

function TrptGlavnaKnjiga.GetSessionParamRelations(
  DataSet: TDataSet): TSessionParamRelations;
begin
  if DataSet = cdsMain then
  begin
    SetLength(Result, 1);
    Result[0].FieldName := 'REF_ID';
    Result[0].SessionName := 'POSLOVNO_LETO_ID';
  end;
end;

procedure TrptGlavnaKnjiga.Initialize;
var
  TitleBand: TExlReportBand;
  MasterDataBand: TExlReportBand;
begin
  inherited;
  TitleBand := rptMain.Bands.AddBand(xlrbtTitle);
  TitleBand.Range := 'A1:D3';
  MasterDataBand := rptMain.Bands.AddBand(xlrbtMasterData);
  MasterDataBand.Range := 'A4:D4';
end;

procedure TrptGlavnaKnjiga.OnFormatCell(Sender: TObject;
  Band: TEXLReportBand; RowInTemplate, RowInReport, ColumnInReport: Integer;
  Report: _Worksheet; const CellValue: OleVariant);
var
  R1, R2: string;
begin
  inherited;
  if (Band.BandType = xlrbtMasterData) and (ColumnInReport = 1) then
  begin
    if Length(VarToStr(CellValue)) = 1 then
    begin
      R1 := 'A' + IntToStr(RowInReport);
      R2 := 'D' + IntToStr(RowInReport);
      Report.Range[R1, R2].Font.Bold := True;
      Report.Range[R1, R2].Font.Size := 9;
      Report.Range[R1, R2].Interior.Color := clLtGray;
      if (RowInTemplate = 4) and (RowInReport > RowInTemplate) then
        Report.Range[R1, R2].EntireRow.PageBreak := xlPageBreakManual;
    end;
  end;
end;

initialization
  RegisterClass(TrptGlavnaKnjiga);

end.
